package nuc.ss.wl.controller;

import nuc.ss.wl.entity.CC;
import nuc.ss.wl.service.CCService;
import nuc.ss.wl.service.ClassService;
import nuc.ss.wl.service.impl.CCServiceImpl;
import nuc.ss.wl.service.impl.ClassServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CCServlet extends BaseServlet {

    public void chooseCourse(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int classno = Integer.parseInt(request.getParameter("classno"));
        int cno = Integer.parseInt(request.getParameter("cno"));
        ClassService classService = new ClassServiceImpl();
        int tno = classService.findById(classno).getTno();
        CCService ccService = new CCServiceImpl();
        CC cc = new CC();
        cc.setClassno(classno);
        cc.setCno(cno);
        cc.setTno(tno);
        int i = ccService.add(cc);
        if (i > 0) {
            response.sendRedirect(request.getContextPath() + "/classServlet?action=findAll");
        } else {

        }
    }
}
